﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 实验报告1._3
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("输入项数：");
            int n = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("圆周率的近似值：");
            Console.WriteLine(getPI(n));
            Console.ReadKey();
        }
        public static double getPI(int count)
        {
            int n = 1;
            double sum = 1;
            double temp = 0.0;
            while(n <count)
            {
                temp = 1.0 / (double)(2 * n + 1);
                if (n % 2 != 0)
                { sum = sum - temp; }
                else
                { sum = sum + temp; }
                n++;
            }
         double PI = 4 * sum;
         return PI;
        }
    }
}
